﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Parts
{
    public partial class CategoryList : SsPart
    {
        public CategoryList()
            : base(new Guid("{576621F9-1A8E-4237-84C5-3F2AC09A70CD}"))
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCategoryList();
            }
        }

        private void BindCategoryList()
        {
            NewsService service = new NewsService();
            _ctlList.DataSource = service.GetCategories().Data;
            _ctlList.DataBind();
        }

        protected void _ctlList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Guid categoryID = new Guid(e.CommandArgument.ToString());
            if (e.CommandName == "Delete")
            {
                NewsService service = new NewsService();
                service.DeleteCategory(categoryID);
            }
        }
    }
}